<?php

namespace App\Models\Goods;

use App\Models\Goods\Cates;
use App\Models\Goods\SpecsItem;
use App\Models\Traits\HashidsHelper;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;

class Specs extends Model
{
     use HashidsHelper;
    protected $table = 'specs';

    protected $fillable = [
        'cate_id','name','sort'
    ];

    protected $datas = ['deleted_at'];

    public function items(){
        return $this->hasMany(SpecsItem::class,'spec_id','id');
    }

    public function cate(){
        return $this->hasOne(Cates::class,'id','cate_id');
    }

    public function setSortAttribute($value)
    {
        return $this->attributes['sort'] = empty($value) ? 0 : $value;
    }

    public function setCateIdAttribute($value)
    {
        return $this->attributes['cate_id'] = Str::after($value,'/');
    }
}
